package com.moge.anjian.service;

import android.accessibilityservice.AccessibilityService;
import android.graphics.Rect;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEventSource;
import android.view.accessibility.AccessibilityNodeInfo;

import com.moge.anjian.MogeAccessibilityManager;


public class MogeAccessibilityService extends AccessibilityService {


    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("dimoge", "服务onCreate");
        MogeAccessibilityManager.setService(this);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        // 监听活动
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_CLICKED) {
            AccessibilityNodeInfo source = event.getSource();
            if (source == null) {
                Log.e("dimoge", "监听事件错误1111");
                return;
            }
            Rect rect = new Rect();
            source.getBoundsInScreen(rect);
            if (rect == null) {
                Log.e("dimoge", "监听事件错误222222");
                return;
            }
            Log.e("dimoge", "监听事件: 点击 x=" + rect.centerX() + ", y = " + rect.centerY() + ", all=" + rect.toString());
        }
    }

    @Override
    public void onInterrupt() {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MogeAccessibilityManager.setService(null);
    }
}
